<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class news extends MY_Controller {
	function __construct(){
		parent::__construct();
		$this->load->model('page_model');
		$this->load->model('article_model');
		$this->load->model('gallery_model');
		$this->load->model('coltypes_model');
	}
	
	//阅读
	public function index($page=1){
		//计算当前页面新闻总条数
		$where=array('audit'=>1,'cid'=>5);
		$config['total_rows'] = $this->db->where($where)->from('article')->count_all_results();
		$config['per_page'] =4;//每页显示的条数
		$config['use_page_numbers'] = TRUE;//默认分页URL中是显示每页记录数,启用use_page_numbers后显示的是当前页码。
		$data['fenye']=$this->article_model->photo_page($config,$page,$where);
		
		$data['seo']=$this->db->get_where('columns',array('id'=>5))->row_array();//获取seo
		$this->load->view('news',$data);
	}
	
	public function news_ajax(){
		$page=$_GET['page'];
		header('Content-type:application/json');
		//计算当前页面新闻总条数
		$where= array('audit'=>1,'cid'=>5);
		$config['total_rows'] = $this->db->where($where)->from('article')->count_all_results();
		$config['per_page'] = 4;//每页显示的条数
		//判断是否有下一页
		if($config['total_rows']>$page*$config['per_page']){
			$back['status']= 'yes';
		}else{
			$back['status']= 'no';
		}
		$config['use_page_numbers'] = TRUE ;//默认分页URL中是显示每页记录数,启用use_page_numbers后显示的是当前页码。
		$data['fenye']=$this->article_model->photo_page($config,$page,$where);
		$html= "";
		foreach ($data['fenye']['new_con'] as $k =>$v){
			$photo=UPLOAD_URL.tag_photo($v['photo']);
			$content=msubstr(str_replace('&nbsp;','',trim(strip_tags($v['content']))),0,90);
			$html.= '<a href="'.site_url('news/info/'.$v['id']).'">
                    <dl>
                        <dt><img src="'.$photo.'" alt=""></dt>
                        <dd>
                            <p>'.date('Y / m / d',$v['timeline']).'</p>
                            <span>'.$v['title'].'</span>
                            <i>'.$content.'</i>
                        </dd>
                    </dl>
                </a>' ;
		}
		$back['list']=$html;
		exit(json_encode($back));
	}
	
	public function info($id=''){
		$data['info']=$this->db->get_where('article',array('cid'=>5,'id'=>$id))->row_array();
		/*新闻上一页，下一页，返回*/
		$data['updown']=$this->article_model->change_page($id,$cid=5);
		$data['seo']=$this->db->get_where('article',array('id'=>$id))->row_array();//获取seo
		$this->load->view('news/info',$data);
	}
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
}